package com.trsvax.gwthello.client.gwtui.widgets;

import com.google.gwt.dom.client.Element;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.LineChart;
import com.google.gwt.visualization.client.visualizations.LineChart.Options;

public class LineChartWidget extends Composite {

	public LineChartWidget(Element element, Dictionary dictionary) {
		LineChart widget = new LineChart(data(), options());
		initWidget(widget);
	}

	public Options options() {
		Options options = Options.create();
		options.setHeight(240);
		options.setTitle("Company Performance");
		options.setWidth(400);
		options.setSmoothLine(true);
		options.setShowCategories(true);
		options.setEnableTooltip(true);
		options.setMin(0);
		options.setMax(2000);
		return options;
	}

	public DataTable data() {
		DataTable data = DataTable.create();
		data.addColumn(ColumnType.STRING, "Year");
		data.addColumn(ColumnType.NUMBER, "Sales");
		data.addColumn(ColumnType.NUMBER, "Expenses");
		data.addRows(4);
		data.setValue(0, 0, "2004");
		data.setValue(0, 1, 1000);
		data.setValue(0, 2, 400);
		data.setValue(1, 0, "2005");
		data.setValue(1, 1, 1170);
		data.setValue(1, 2, 460);
		data.setValue(2, 0, "2006");
		data.setValue(2, 1, 660);
		data.setValue(2, 2, 1120);
		data.setValue(3, 0, "2007");
		data.setValue(3, 1, 1030);
		data.setValue(3, 2, 540);
		return data;

	}

}
